define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'pay/payrecycle/index',
                    del_url: 'pay/payrecycle/del',
                    restore_url: 'pay/payrecycle/restore',
                    table: 'pay',
                },
                pageSize: 5, //调整分页大小为20
                pageList: [5, 10, 20, 30]
            });


            var table = $("#table");
            // 初始化表格
            table.bootstrapTable({
                // 当访问列表发起ajax请求数据
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                // 主键
                pk: 'id',
                // 设置默认排序
                sortName: 'createtime',
                sortOrder: 'desc',
                search: false, // 取消快速搜索框
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        { checkbox: true },
                        { field: 'id', title: __('Id'), sortable: true },
                        { field: 'code', title: __('Code') },
                        { field: 'name', title: __('Name'), operate: 'LIKE' },
                        { field: 'third', title: __('Third'), searchable: false },
                        { field: 'paytype', title: __('Paytype'), searchList: { "0": __('微信支付'), "1": __('支付宝支付') }, formatter: Table.api.formatter.normal },
                        { field: 'originalprice', title: __('Originalprice') },
                        { field: 'price', title: __('Price') },
                        { field: 'status', title: __('Status'), searchList: { "0": __('待支付'), "1": __('已支付'), "2": __('已关闭') }, formatter: Table.api.formatter.status },
                        { field: 'createtime', title: __('Ceatetime'), operate: 'RANGE', addclass: 'datetimerange', formatter: Table.api.formatter.datetime },
                        { field: 'paytime_text', title: __('Paytime'), operate: 'RANGE', addclass: 'datetimerange', formatter: Table.api.formatter.datetime },
                        {
                            field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate,
                            buttons: [
                                {
                                    name: '课程还原',
                                    title: __('还原'),
                                    classname: 'btn btn-success btn-xs btn-ajax',
                                    icon: 'fa fa-reply',
                                    url: 'pay/payrecycle/restore',
                                    extend: 'data-toggle="tooltip" data-container="body"',
                                    confirm: '确定还原吗',
                                    refresh: true, //操作完成后是否刷新列表
                                }]
                        }
                    ]
                ]
            })
            $(".pay").click(function () {
                $ids = Table.api.selectedids(table)
                layer.confirm('确定还原' + $ids.length + "条数据吗?", { icon: 3, title: '提示' }, function (index) {
                    if (index) {
                        Backend.api.ajax("pay/payrecycle/restore?ids=" + $ids.join(","), function (response) {
                            // 处理返回的结果
                            layer.close(index);
                            table.bootstrapTable('refresh')

                        })
                    }
                    layer.close(index);
                });
            }),
                // 为表格绑定事件
                Table.api.bindevent(table);
        },
        del: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    }

    return Controller;
});
